package com.dong.springboot.web.autoconfigure;

import com.dong.springboot.web.config.AuthorSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类
 *
 * @author yangjian19
 * @date 2018/8/8
 */
@Configuration
@EnableConfigurationProperties(AuthorSettings.class)
@ConditionalOnClass(AuthorService.class)
@ConditionalOnProperty(prefix = "author", value = "enabled", matchIfMissing = true)
public class AuthorServiceAutoConfiguration {

    @Autowired
    private AuthorSettings authorSettings;

    @Bean
    @ConditionalOnMissingBean(AuthorService.class)
    public AuthorService authorService() {
        AuthorService authorService = new AuthorService();
        authorService.setAuthorName(authorSettings.getName());
        return authorService;
    }
}
